﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Work.Tools.Logger;
using Work.UI.Web.Forms.Code.Common;
using Work.UI.Web.Forms.Code.Security;

namespace Work.UI.Web.Forms
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            IoCContainer.Initialize();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            ISercurityService securityService = IoCContainer.ServiceLocator.Resolve<ISercurityService>();
            securityService.RefreshPrincipal();
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            //try
            //{
            //    Exception lastError = Server.GetLastError();
            //    if (lastError != null)
            //    {
            //        ILogger logger = IoCContainer.ServiceLocator.Resolve<ILogger>();
            //        logger.Error(lastError);
            //        Server.Transfer("~/Error/Default.aspx");
            //    }
            //}
            //catch
            //{
            //    Response.Write("Unexpected error has occured");
            //}
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            IoCContainer.Dispose();
        }
    }
}